package com.jyb.qiyefuwu.view.adpater;

import android.content.Context;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jyb.qiyefuwu.BR;
import com.jyb.qiyefuwu.R;
import com.jyb.qiyefuwu.entity.ServiceNodeBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;


public class ServiceOderNodeAdapter extends BaseRecycleAdapter<ServiceNodeBean> {

    private ImageView iv_line_golden;
    private ImageView iv_line_grey;
    private ImageView img_golden;
    private ImageView img_grey;
    private ImageView iv_line1;
    private ImageView iv_line2;
    private ImageView tv_blank_place;
    private ImageView tv_blank_place2;
    private TextView iv_title;
    private TextView iv_content;
    private TextView tv_tips;
    private TextView tv_reason;
    private int s;


    public ServiceOderNodeAdapter(Context context, List<ServiceNodeBean> datas) {
        super(context, R.layout.item_service_oder_node, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final ServiceNodeBean entity) {
        holder.setBinding(BR.viewModel, entity);
        iv_line_golden = holder.itemView.findViewById(R.id.iv_line_golden);
        iv_line_grey = holder.itemView.findViewById(R.id.iv_line_grey);
        img_golden = holder.itemView.findViewById(R.id.img_golden);
        img_grey = holder.itemView.findViewById(R.id.img_grey);

        iv_line1 = holder.itemView.findViewById(R.id.iv_line1);
        iv_line2 = holder.itemView.findViewById(R.id.iv_line2);
        iv_title = holder.itemView.findViewById(R.id.iv_title);
        iv_content = holder.itemView.findViewById(R.id.iv_content);
        tv_blank_place = holder.itemView.findViewById(R.id.tv_blank_place);
        tv_blank_place2 = holder.itemView.findViewById(R.id.tv_blank_place2);
        tv_tips = holder.itemView.findViewById(R.id.tv_tips);
        tv_reason = holder.itemView.findViewById(R.id.tv_reason);

        if (entity.getTime() == null) {
            //有节点
            //圆
            img_golden.setVisibility(View.GONE);
            img_grey.setVisibility(View.VISIBLE);
            //线
            iv_line_golden.setVisibility(View.GONE);
            iv_line_grey.setVisibility(View.VISIBLE);
            if (s == 0) {
                iv_line1.setVisibility(View.VISIBLE);
                iv_line2.setVisibility(View.GONE);
                iv_line1.setVisibility(holder.getIndex_position() == 0 ? View.INVISIBLE : View.VISIBLE);
            } else {
                iv_line1.setVisibility(View.GONE);
                iv_line2.setVisibility(View.VISIBLE);
                iv_line2.setVisibility(holder.getIndex_position() == 0 ? View.INVISIBLE : View.VISIBLE);
            }
            iv_line_grey.setVisibility(holder.getIndex_position() == datas.size() - 1 ? View.GONE : View.VISIBLE);
            s = s + 1;
        } else {
            //无节点
            //圆
            img_golden.setVisibility(View.VISIBLE);
            img_grey.setVisibility(View.GONE);
            //线
            iv_line_golden.setVisibility(View.VISIBLE);
            iv_line_grey.setVisibility(View.GONE);
            iv_line1.setVisibility(View.VISIBLE);
            iv_line2.setVisibility(View.GONE);
            iv_line_golden.setVisibility(holder.getIndex_position() == datas.size() - 1 ? View.GONE : View.VISIBLE);
            iv_line1.setVisibility(holder.getIndex_position() == 0 ? View.INVISIBLE : View.VISIBLE);
        }
        iv_title.setText(entity.getName());
        if (!TextUtils.isEmpty(entity.getTime())) {
            iv_content.setText(DateUtils.stampToDate(entity.getTime()));
            iv_content.setVisibility(View.VISIBLE);
            iv_title.setTextColor(context.getResources().getColor(R.color.color_B79255));
            iv_title. setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        } else {
            iv_content.setVisibility(View.GONE);
            iv_title.setTextColor(context.getResources().getColor(R.color.color_333333));
            iv_title. setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        }
        if ("订单关闭".equals(entity.getName())) {
            tv_blank_place.setVisibility(View.GONE);
            tv_tips.setVisibility(View.VISIBLE);
            tv_reason.setVisibility(!TextUtils.isEmpty(entity.getReason()) ? View.VISIBLE : View.GONE);
            tv_blank_place2.setVisibility(View.VISIBLE);
        }
    }
}
